/**
 * <p>cceaf辅助类</p>
 * xtype = cceafajaxhelper

 * @module Ext-ux-cceaf-util
 * @class cceaf.util.CceafHelper
 * @extends Object
 * @static
 * @since 1.0
 */
Ext.ns('cceaf.util');

Ext.define('cceaf.util.CceafHelper',{
	//extjs cmd只能通过类查找，需定义空类
});

cceaf.util.CceafHelper = (function() {
	
	return {
		
		/**
		 * 设置Cookie
		 * 
		 * @param {String} name Cookie名称 
		 * @param {String} value Cookie值
		 * @return
		 */
		setCookie: function(name, value,expires) {
			if (expires != null) {
				var LargeExpDate = new Date();
				LargeExpDate.setTime(LargeExpDate.getTime()
						+ (expires * 1000 * 3600 * 24));
			}
			document.cookie = name
					+ "="
					+ escape(value)
					+ ((expires == null) ? "" : ("; expires=" + LargeExpDate
							.toGMTString()));
		},

		/**
		 * 获取Cookie
		 * 
		 * @param {String} Name Cookie名称 
		 * @return {String} Cookie值
		 */
		getCookie: function(Name) {
			var search = Name + "="
			if (document.cookie.length > 0) {
				offset = document.cookie.indexOf(search)
				if (offset != -1) {
					offset += search.length
					end = document.cookie.indexOf(";", offset)
					if (end == -1)
						end = document.cookie.length
					return unescape(document.cookie.substring(offset, end))
				} else
					return ""
			}
		},

		/**
		 * 从缓存中清除Cookie
		 * 
		 * @param {String} name Cookie名称
		 * @return
		 */
		clearCookie: function(name) {
			var expdate = new Date();
			expdate.setTime(expdate.getTime() - (86400 * 1000 * 1));
			setCookie(name, "", expdate);
		},
		
		/**
		 * 打开对话框
		 *
		 * @param {String} pUrl 打开窗口的URL
		 * @param {Number} pWidth 窗口宽度
		 * @param {Number} pHeight 窗口高度
		 * @return
		 */
		openUrl: function(pUrl, pWidth, pHeight) {
			//alert(pUrl);
			
			if (Ext.isEmpty(pWidth)) {
				pWidth = 800;
			}
			
			if (Ext.isEmpty(pHeight)) {
				pHeight = 600;
			}
			
			var left = (screen.width - pWidth) / 2;
			var top = (screen.height - pHeight) / 2;
			var str = 'width='
					+ pWidth
					+ ',height='
					+ pHeight
					+ ',top='
					+ top
					+ ",left="
					+ left
					+ ',toolbar=no,menubar=no,scrollbars=no,resizable=yes,location=no,status=no';
			window.open(pUrl, '', str);
		}
		
	};
	
}());
